feat(ha): treat notificationComplete as stateless event like action#31686
feat(ha): treat notificationComplete as stateless event like action#31686rohankapoorcom wants to merge 3 commits intoKoenkk:devfrom
Conversation
Extend Home Assistant extension handling so notificationComplete follows the same pattern as action: clear from cached state after publish (always, unlike action which clears only with legacyActionSensor), publish the value to a dedicated MQTT topic for device triggers, and run device trigger discovery. Adds STATELESS_EVENT_PROPERTIES to list event-like state keys; skip empty values to avoid re-entrant clears. Supports Inovelli ledEffectComplete (zigbee-herdsman-converters) without overloading the action property. Made-with: Cursor
04ade77 to
d68f93f
Compare
Add integration tests for STATELESS_EVENT_PROPERTIES: MQTT device trigger discovery, dedicated topic, state clear on json output, and no device_automation when output is attribute. Made-with: Cursor
Made-with: Cursor
|
I would propose to rename |
|
The switches already send an |
|
What about |
|
There's a bunch of different values though, not just one and we need to know which one is returned: |
|
Agreed with the no-more-action-like props decision. It would too quickly become a nightmare for both dev maintenance and user usage patterns. |
I'm not 100% familiar with Z2M (I use ZHA), but yes, the switch in question broadcasts that the notification is dismissed through this event. And there are many possible values it passes along with it for combination(s) of LEDs that are no longer being used for the notification. My understanding is that it'll be much easier to code this if the Hopefully this helps and/or @rohankapoorcom or @MrDaGree could better clarify. |
If your question is do we need to know whether the notification is complete, yes. @wbyoung made a notification manager for Inovelli switches. It needs to know which notifications that were triggered are still running and the only way to know that is to get the completion event. If the question is do we need to clear the notification completion event, I believe so. The problem otherwise is that the state becomes "sticky" and the notification manager has no idea what it is referring to when the notification completion doesn't change. Here's an example workflow:
Please let me know if you can think of another way to handle this. |
|
Could this maybe be exposed as a binary which goes to |
Probably not. The notification complete contains several possible payloads (for ALL_LEDS or LED_1-LED_7 getting completed). |
|
I don't see why that would expose blocking each led as a binary, in case |
|
How would a binary help here? How do they get "reset" and set back to false? Don't we still have the same problem?
|
|
If I understand correctly, this will give the following behaviour: Start situation:
State change:
State change:
Can detect the change because
State change:
State change: Would that solve the issue? |
Maybe. But it's maybe also conflating the state of the LED(s) and the state of the notification. We want just the state of the notification (which may be what you were after, but just using abbreviated names to write it all more quickly). These switches are a little funny in how they display things:
So all and individual are mutually exclusive. If the goal is for Z2M to consider this and try to show the state of active notifications, then it may need to have the same underlying setup. I think the following would need to be the flags (rather than just the on/off state for an individual LED):
And then each of those can be on/off. For reference, here are the values found for the (Also, in your example above, was the final stage change supposed to be to |
|
I'm worried that we're basically just introducing a lot of state tracking into Z2M for very little benefit when we have a transient event and just want to pass that transient event along to let the consuming service manage that. One problem with tracking all of these states is when a switch is rebooted (through a power issue or the air gap being pulled). When the switch powers on again, Z2M would have no way to know that all of the notifications have been reset (and no way to query and find that out). So this state would end up horribly out of sync. |
I 100% agree with you here. This is certainly an issue in the integration I'm working on, but that seems like a better place to explain that it's not possible than having Z2M introduce that idea and field all of the support for it. If I decide in my integration (or whatever I'm using Z2M for) that I'm willing to accept the trade-off, then that's on me. But as a general idea it seems like Z2M should expose an event when the underlying device is emitting an event, and state when the device is reporting to be in a certain state. Specifically in this case there's only the event. There's no way (currently) to query for the state. Event/action seem interchangeable to me, though again don't know Z2M well. But event/action is what I'd want to consume ideally (not state). |
Yeah, I agree. The only way I know besides this PR would be to overload these events into the existing action event which is where all of the user oriented actions (multi tap / scene controls) are controlled from. I really don't like the idea of combining them but I would prefer that to tracking state here. On the Z-Wave switches this is just exposed as a separate event as well as far as I can tell. |
Summary
Extend the Home Assistant extension so
notificationCompleteis handled likeaction: clear from cached state after publish, publish to a dedicated MQTT topic for device triggers, and run device trigger discovery.Behavior
action: unchanged — clear only whenlegacyActionSensoris enabled.notificationComplete: always cleared after publish so the last LED effect completion does not linger in state.zigbee2mqtt/<device>/<key>and device trigger discovery runs.Motivation
Supports Inovelli
ledEffectComplete(from zigbee-herdsman-converters) as a one-off event without overloading theactionproperty.Related context:
Implementation
STATELESS_EVENT_PROPERTIES(action,notificationComplete).undefinedor empty string values to avoid re-entrant clears.Made with Cursor